package apacheCommonsTest.lang.string;

import org.apache.commons.lang3.StringUtils;

public class Main {
    public static void main(String[] args) {
//        empty();
//        blank();
//        trim();
//        truncate();
//        strip();
//        equals();
//        indexOf();
//        contains();
//        substring();
        leftMidRight();
    }

    public static void leftMidRight(){
        System.out.println(StringUtils.left("abcd",2));
        System.out.println(StringUtils.mid("abcd",1,2));
        System.out.println(StringUtils.right("abcd",2));

        System.out.println(StringUtils.leftPad("abcd",5));
        System.out.println(StringUtils.rightPad("abcd",2));


    }
    /**
     * substring
     */
    public static void substring(){
        System.out.println(StringUtils.substring("abcd",0));
        System.out.println(StringUtils.substring("abcd",0,2));
        System.out.println(StringUtils.substring("abcd",0,2));
        System.out.println(StringUtils.substringBetween("abcdabcd","cd","cd"));
        System.out.println(StringUtils.substringAfter("abcdabcd","cd"));

    }
    /**
     * contains 判断是否包含
     */
    private static void contains(){
        System.out.println(StringUtils.containsAny("rieuhugdsfjh2b1kj3jdsf","h","j","jd"));
        System.out.println(StringUtils.containsWhitespace("rieuhugdsfjh2b1kj3jd sf"));
        System.out.println(StringUtils.containsNone("rieuhugdsfjh2b1kj3jd sf"));
        System.out.println(StringUtils.containsAny("rieuhugdsfjh2b1kj3jd sf","j3","jd"));
        //查看后者是否包含前者的所有字符
        System.out.println(StringUtils.containsOnly("abcccp","abcp"));
        //查看后者是否不包含前者的所有字符
        System.out.println(StringUtils.containsNone("abcccp","xyz"));
//        System.out.println(StringUtils.containsAny("rieuhugdsfjh2b1kj3jd sf","j3","jd"));
    }

//    private static void

    /**
     * empty方法可以判断一个字符串或数组是否为空（null 或 “”）
     */
    private static void empty(){
        System.out.println(StringUtils.isEmpty("xxx"));
        System.out.println(StringUtils.isEmpty(""));
        System.out.println(StringUtils.isEmpty(null));
        System.out.println(StringUtils.isAllEmpty(null,""));
    }

    /**
     * blank方法用于判断字符串或字符串数组是否为空白 "" " " null
     */
    private static void blank(){
        System.out.println(StringUtils.isBlank("  "));
        System.out.println(StringUtils.isBlank(null));
        System.out.println(StringUtils.isBlank(""));
        System.out.println(StringUtils.isAllBlank("  "," ",""));
    }

    /**
     *  trim去除字符间的空格
     */
    private static void trim(){
//        String x = ""
        System.out.println(StringUtils.trim("  "));
        System.out.println(StringUtils.trim("  asd "));

        System.out.println(StringUtils.trimToNull("  "));
        System.out.println(StringUtils.trimToNull("  asd "));

        System.out.println(StringUtils.trimToEmpty("  "));
        System.out.println(StringUtils.trimToNull("  asd "));
        System.out.println(StringUtils.trimToNull(null));
    }

    /**
     * truncate 截短字符 规定起始位置
     */
    private static void truncate(){
        System.out.println(StringUtils.truncate("ewqtrweqweqweq",5));
        System.out.println(StringUtils.truncate("ewqtrweqweqwe34qn",5,10));
    }
    /**
     * strip 去除字符串首或尾空格 或者特定的字符串
     */
    private static void strip(){
        System.out.println(StringUtils.strip(" s a fafs "));
        System.out.println(StringUtils.strip("1 s a fafs 1","1"));
        System.out.println(StringUtils.stripStart("1 s a fafs 1","1"));
        System.out.println(StringUtils.stripAccents("1 s a fafs 1"));

    }
    /**
     * equal 相等，可以忽略大小写，并且可以匹配一个数组里面的所有元素
     */
    private static void equals(){
        System.out.println(StringUtils.equalsIgnoreCase("abc","ABc"));
        System.out.println(StringUtils.equalsAny("abc","ABc","abc","adsc"));
    }
    /**
     * indexOf 查看字符串的位置 ordinalIndexOf根据出现的序号查看
     */
    private static void indexOf(){
        System.out.println(StringUtils.indexOf("elioyhgiehnjohcxgoioiowqu2891","cx"));
        System.out.println(StringUtils.lastIndexOf("elioyhgiehnjohcxgoioiowqu2891","o"));
        System.out.println(StringUtils.ordinalIndexOf("elioyhgiehnjohcxgoioiowqu2891","o",2));
        System.out.println(StringUtils.lastOrdinalIndexOf("elioyhgiehnjohcxgoioiowqu2891","o",3));
        //搜索后面字符串中的字符第一次位置
        System.out.println(StringUtils.indexOfAny("elioyhgiehnjohcxgoioiowqu2891","hgi","gie"));
        System.out.println(StringUtils.lastIndexOfAny("elioyhgiehnjohcxgoioiowqu2891","hgi","gie"));
        //搜索一个字符串中包含的后者字符中最靠前的位置
        System.out.println(StringUtils.indexOfAnyBut("elioyhgiehnjohcxgoioiowqu2891","gei"));
    }


}
